//@author A0081229H
package storage;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;

public class StorageLogger {
	private static final String filePath = "storage_log.txt";
	private static final String NEWLINE = "\r\n";
	private static StorageLogger self = null;
	private static LinkedList<String> logQueue;
	
	public StorageLogger() throws IOException {
		PrintWriter storageLogger = new PrintWriter(new FileWriter(filePath, true), true);
		storageLogger.close();
	}
	
	public static void create() throws IOException {
		self = new StorageLogger();
		logQueue = new LinkedList<String>();
	}
	
	public static void log(String method) throws IOException {
		logQueue.add(method);
		writeLog();
	}
	
	private static void writeLog() throws IOException {
		PrintWriter storageLogger = new PrintWriter(new FileWriter(new File(filePath), true), true);
		String method = logQueue.poll();
		storageLogger.write(method);
		storageLogger.write(NEWLINE);
		storageLogger.close();
	}
	
	
}
